package com.spark.core.action

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object Demo6_reduce {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf().setAppName("countByKey").setMaster("local")
    val sc = new SparkContext(conf)
    sc.setLogLevel("error")

    val rdd: RDD[Int] = sc.parallelize(Array[Int](1, 2, 3, 4, 5))
    val result: Int = rdd.reduce((v1: Int, v2: Int) => {
      v1 + v2
    })

    println(result)

  }
}
